
package com.neutech.day01.homework;

import java.util.Arrays;
import java.util.Random;

class VerificationCode {
    public static void main(String[] args) {
        char[] verificationCode = getVerificationCode();
        System.out.print("生成的验证码为：");
        for (int i = 0;i<4;i++) {
            System.out.print(verificationCode[i]);
        }
        System.out.println();
        lottery();
    }

    public static char[] getVerificationCode() {
        Random r = new Random();
        char[] codeLib = {'3','4','5','6','7','8','a','A','b','B','c','C','d','D','e','E','f','F','G','h','H','i','I','j','J',
                'k','K','m','M','n','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z'};
        char[] result = new char[4];
        for(int i = 0;i<4;i++) {
            int index =  r.nextInt(codeLib.length);
            result[i] = codeLib[index];
            char temp = codeLib[index];
            codeLib[index] = codeLib[codeLib.length - 1];
            codeLib[codeLib.length - 1] = temp;
        }
        return result;
    }
    // 验证码生成
    public static void lottery() {
        String[] redResult = {};
        String[] redBallPoll = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18",
                "19","20","21","22","23","24","25","26","27","28","29","30","31","32","33"};
        String[] blueBallPoll = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16"};
        Random r = new Random();
        String temp = "";
        for (int i = 0;i<=5;i++) {
            int redIndex = r.nextInt(redBallPoll.length);
            redResult = Arrays.copyOf(redResult,redResult.length + 1);
            redResult[redResult.length - 1] = redBallPoll[redIndex];
            temp = redBallPoll[redIndex];
            redBallPoll[redIndex] = redBallPoll[redBallPoll.length - 1];
            redBallPoll[redBallPoll.length - 1] = temp;
            redBallPoll = Arrays.copyOf(redBallPoll,redBallPoll.length - 1);
        }
        String[] blueResult = {};
        int blueIndex = r.nextInt(blueBallPoll.length);
        blueResult = Arrays.copyOf(blueResult,blueResult.length + 1);
        blueResult[blueResult.length - 1] = blueBallPoll[blueIndex];
        System.out.println("摇号结果为：" + Arrays.toString(redResult) + Arrays.toString(blueResult));
    }
}

